﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NFLManager
{
    public partial class ProgressForm : Form
    {
        protected static ProgressForm _progressForm = null;

        private Stopwatch stopwatch = new Stopwatch();

        protected ProgressForm()
        {
            InitializeComponent();
        }

        public long ElapsedTime
        {
            get { return stopwatch.ElapsedMilliseconds; }
        }

        public static ProgressForm Istance
        {
            get { return _progressForm ?? (_progressForm = new ProgressForm()); }
        }

        public void AddProgress()
        {
            progressBar.PerformStep();
            var percentage = ((float)progressBar.Value / progressBar.Maximum) * 100;
            lblPercentage.Text = percentage + "%";
            lblPercentage.Refresh();
            lblElapsedTime.Text = GetElapsedTime();
            lblElapsedTime.Refresh();
        }

        public void SetProgressBar(int max, int step)
        {
            progressBar.Maximum = max;
            progressBar.Step = step;
        }

        public void StartTimer()
        {
            stopwatch.Start();
        }

        public void StopTimer()
        {
            stopwatch.Stop();
        }

        public string GetElapsedTime()
        {
            TimeSpan t = TimeSpan.FromMilliseconds(ElapsedTime);
            string result = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
                                t.Hours,
                                t.Minutes,
                                t.Seconds);
            return result;
        }
        
    }
}
